﻿using Ec_System.Bll.Web;
using Ec_System.Models.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ec_System.Facade.Web
{
    public class CustomerFacade
    {
        CustomerManager customerManager = new CustomerManager();
        // <summary>
        /// 检测用户名是否存在
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns>True -- 不存在,FALSE-- 存在</returns>
        public bool IsContainUsername(string loginID)
        {
            return !customerManager.GetCustomerCountByLoginID(loginID);
            
        }

        /// <summary>
        /// 检测Email是否存在
        /// </summary>
        /// <param name="email"></param>
        /// <returns>True -- 不存在,FALSE-- 存在</returns>
        public bool IsContainEmail(string email)
        {
            return !customerManager.GetCustomerCountByEmail(email);
        }

        /// <summary>
        /// 检测电话号码是否存在
        /// </summary>
        /// <param name="email"></param>
        /// <returns>True -- 不存在,FALSE-- 存在</returns>
        public bool IsContainTel(string tel)
        {
            return !customerManager.GetCustomerCountByTel(tel);
        }

        /// <summary>
        /// 讲注册的用户信息入库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddCustomer(CustomerData model)
        {
            return customerManager.AddCustomer(model);
        }

        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public CustomerData UserLoginValidate(CustomerData model)
        {
            return customerManager.UserLoginValidate(model);
        }

        /// <summary>
        /// 根据LoginID获取用户信息
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public CustomerData GetUserInfoByLoginID(string loginID)
        {
            return customerManager.GetUserInfoByLoginID(loginID);
        }

        /// <summary>
        /// 根据LoginID获取用户信息(带订单信息)
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public CustomerData GetUserInfoAndOrderInfoByLoginID(string loginID)
        {
            ItemOrderManager itemOrderManager = new ItemOrderManager();
            var model = customerManager.GetUserInfoByLoginID(loginID);
            model.OrderList = itemOrderManager.GetTop5OrderByLoginID(loginID);

            return model;
        }

        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateUserInfoByLoginID(CustomerData model)
        {
            return customerManager.UpdateUserInfoByLoginID(model);
        }

        /// <summary>
        /// 更新用户密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateUserPwdByLoginID(CustomerData model)
        {
            return customerManager.UpdateUserPwdByLoginID(model);
        }

        /// <summary>
        /// 根据LoginID获取用户信息及其收货地址
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public CustomerData GetUserInfoAndAddressInfoByLoginID(string loginID)
        {
            return customerManager.GetUserInfoAndAddressInfoByLoginID(loginID);
        }


    }
}
